package com.tjp.eight.views;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;

import com.tjp.eight.R;

/**
 * Created by Administrator on 2017/3/21.
 */

public class SelectPicDialog extends Dialog implements View.OnClickListener {
    private Context context;
    private Button btn_pz;
    private Button btn_pic;
    public static final int TYPE_PIC = 0x01;
    public static final int TYPE_XJ = 0x02;
    private OnItemClickListener onItemClickListener;

    public SelectPicDialog(Context context) {
        super(context, R.style.Dialog);
        this.context = context;
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_select_pic, null);
        btn_pz = (Button) view.findViewById(R.id.btn_pai_zha);
        btn_pic = (Button) view.findViewById(R.id.btn_xia_ce);
        btn_pic.setOnClickListener(this);
        btn_pz.setOnClickListener(this);

        setContentView(view);

        WindowManager.LayoutParams lp = getWindow().getAttributes();
        Display display = getWindow().getWindowManager().getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);
        lp.width = point.x;
        lp.gravity = Gravity.BOTTOM;
        lp.alpha = 1.0f;
        getWindow().setAttributes(lp);
        setCanceledOnTouchOutside(true);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_pai_zha:
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(TYPE_XJ);
                }
                dismiss();
                break;
            case R.id.btn_xia_ce:
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(TYPE_PIC);
                }
                dismiss();
                break;
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(int type);
    }
}
